package raft

import (
    "fmt"
)

// appendEntry 添加日志条目
func (rf *Raft) appendEntry(entry LogEntry) {
    rf.mu.Lock()
    defer rf.mu.Unlock()
    rf.log = append(rf.log, entry)
    fmt.Printf("Node %d appended log: %s\n", rf.me, entry.Command)
}

// executeLogEntry 执行日志条目
func (rf *Raft) executeLogEntry(entry LogEntry) {
    var x int
    fmt.Sscanf(entry.Command, "x = %d", &x)

    switch {
    case entry.Command == "x = x + 1":
        x += 1
    case entry.Command == "x = x * 2":
        x *= 2
    }

    fmt.Printf("Node %d executed command: %s, result: %d\n", rf.me, entry.Command, x)
}
